package com.zxh.dao.user;


import com.zxh.dao.BaseDao;
import com.zxh.pojo.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao{
    @Override
    public User getLoginUser(Connection con, String userCode) throws SQLException {
        User us = null;
        PreparedStatement pst = null;
        ResultSet rst = null;
        if (con == null)
            return null;

        String sql = "select * from smbms_user where userCode = ?";
        Object[] params = {userCode};
        rst = BaseDao.execute(con, pst, rst, sql, params);
        if( rst.next() ){
            us = new User();
            us.setId(rst.getInt("id"));
            us.setUserCode(rst.getString("userCode"));
            us.setUserName(rst.getString("userName"));
            us.setUserPassword(rst.getString("userPassword"));
//            us.setGender(rst.getInt("gender"));
            us.setBirthday(rst.getDate("birthday"));
            us.setPhone(rst.getString("phone"));
            us.setAddress(rst.getString("address"));
//            us.setUserRole(rst.getInt("userRole"));
//            us.setCreatedBy(rst.getInt("createdBy"));
            us.setCreationDate(rst.getTimestamp("creationDate"));
            us.setModifyBy(rst.getInt("modifyBy"));
            us.setModifyDate(rst.getTimestamp("modifyDate"));
        }
        BaseDao.closeResult(null, pst, rst);
    return us;
    }
}
